import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEqual from "lodash/isEqual";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _class, _class2;

/**
 * index - 调度日志
 * @date: 2018-9-17

 * TODO: 国际化
 */
import React from 'react'; // import ReactDOM from 'react-dom';

import { connect } from 'dva';
import { Form, Button, Table, DatePicker, Select, Row, Col, Popconfirm, Input } from 'antd';
import { Bind } from 'lodash-decorators';
import moment from 'moment';
import { Header, Content } from 'components/Page';
import Lov from 'components/Lov';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import formatterCollections from 'utils/intl/formatterCollections';
import notification from 'utils/notification';
import { getDateTimeFormat, getCurrentOrganizationId, isTenantRoleLevel, tableScrollWidth } from 'utils/utils';
import { DEFAULT_TIME_FORMAT, DEFAULT_DATETIME_FORMAT, SEARCH_FORM_ROW_LAYOUT, FORM_COL_4_LAYOUT, SEARCH_FORM_ITEM_LAYOUT } from 'utils/constants';
import { dateTimeRender, TagRender, operatorRender } from 'utils/renderer';
import { CPAAS_FILE, BKT_SDR } from 'utils/config';
import { downloadFile } from 'cpaas-front/lib/services/api';
import ErrorModal from "./ErrorModal";
import LogModal from "./LogModal";
import ProgressModal from "../components/ProgressModal";
import ClearLogsDrawer from "./ClearLogsDrawer";
var expandFormStyle = {
  display: ''
};
var noExpandFormStyle = {
  display: 'none'
};
var JobLog = (_dec = connect(function (_ref) {
  var loading = _ref.loading,
      jobLog = _ref.jobLog;
  return {
    jobLog: jobLog,
    fetchList: loading.effects['jobLog/fetchLogsList'],
    clearLogLoading: loading.effects['jobLog/clearLogs'],
    errorDetailLoading: loading.effects['jobLog/fetchErrorDetail'],
    logDetailLoading: loading.effects['jobLog/fetchLogDetail'],
    dateTimeFormat: getDateTimeFormat(),
    tenantId: getCurrentOrganizationId(),
    tenantRoleLevel: isTenantRoleLevel()
  };
}), _dec2 = Form.create({
  fieldNameProp: null
}), _dec3 = formatterCollections({
  code: ['csdr.jobLog']
}), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec14 = Bind(), _dec15 = Bind(), _dec16 = Bind(), _dec17 = Bind(), _dec18 = Bind(), _dec19 = Bind(), _dec20 = Bind(), _dec21 = Bind(), _dec22 = Bind(), _dec23 = Bind(), _dec24 = Bind(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(JobLog, _React$Component);

  var _super = _createSuper(JobLog);

  function JobLog(props) {
    var _this;

    _classCallCheck(this, JobLog);

    _this = _super.call(this, props);
    _this.pullCatTimer = void 0;
    _this.progressTimer = void 0;
    _this.state = {
      modalVisible: false,
      // 控制调度日志模态框显示
      detailVisible: false,
      handleMsgVisible: false,
      // 执行日志模态框
      clearLogsVisible: false,
      // 清除日志模态框
      detailData: {},
      // 调度详情数据
      triggerMsgData: {},
      // 调度日志详情数据
      clearParamsData: {},
      pullLoading: true,
      // 加载Spin显示与否
      logContent: '',
      // 拉取到的日志内容
      tipsMessage: '',
      // 提示内容
      queryParams: {},
      fromLineNum: 1,
      // [from, to], start as 1
      pullFailCount: 0,
      // 拉取次数(最大值为20)
      expandForm: false,
      errorVisible: false,
      errorDetail: '',
      // 错误详情数据
      logVisible: false,
      logDetail: '',
      // 日志详情数据
      progressVisible: false,
      progressValue: {}
    };
    return _this;
  }

  _createClass(JobLog, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this$props = this.props,
          dispatch = _this$props.dispatch,
          skipQuery = _this$props.jobLog.skipQuery;
      dispatch({
        type: 'jobLog/init'
      });
      this.fetchLogsList({
        jobId: skipQuery.jobId
      }); // this.fetchLogsList({ jobId: params.jobId });
    } // eslint-disable-next-line

  }, {
    key: "UNSAFE_componentWillReceiveProps",
    value: function UNSAFE_componentWillReceiveProps(nextProps) {
      if (!_isEqual(nextProps.jobLog.skipQuery, this.props.jobLog.skipQuery)) {
        this.fetchLogsList({
          jobId: nextProps.jobLog.skipQuery.jobId // groupId: nextProps.jobLog.skipQuery.groupId,

        });
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.handleClearTimer();
      this.clearProgressTimer();
      this.props.dispatch({
        type: 'jobLog/updateState',
        payload: {
          skipQuery: {}
        }
      });
    } // 清除定时器

  }, {
    key: "handleClearTimer",
    value: function handleClearTimer() {
      clearInterval(this.pullCatTimer);
      this.pullCatTimer = null;
    } // 清除进度获取定时器

  }, {
    key: "clearProgressTimer",
    value: function clearProgressTimer() {
      clearInterval(this.progressTimer);
      this.progressTimer = null;
    }
    /**
     * 日志清理
     * @param {object} fieldsValue - 请求参数
     */

  }, {
    key: "handleClearLogs",
    value: function handleClearLogs(fieldsValue) {
      var _this2 = this;

      var _this$props2 = this.props,
          dispatch = _this$props2.dispatch,
          pagination = _this$props2.jobLog.pagination;
      dispatch({
        type: 'jobLog/clearLogs',
        payload: _objectSpread(_objectSpread({}, this.state.groupsData), fieldsValue)
      }).then(function (res) {
        if (res) {
          notification.success();

          _this2.handleClearLogsModalVisible(false);

          _this2.fetchLogsList({
            page: pagination.current - 1,
            size: pagination.pageSize
          });
        }
      });
    }
    /**
     * @function fetchPortalAssign - 获取列表数据
     * @param {object} params - 查询参数
     * @param {number} params.page - 页码
     * @param {number} params.size - 页数
     */

  }, {
    key: "fetchLogsList",
    value: function fetchLogsList() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$props3 = this.props,
          dispatch = _this$props3.dispatch,
          form = _this$props3.form,
          query = _this$props3.jobLog.query;
      var values = form.getFieldsValue();
      var timeStart = values.timeStart,
          timeEnd = values.timeEnd;
      var jobId = params.jobId ? params.jobId : values.jobId;
      dispatch({
        type: 'jobLog/fetchLogsList',
        payload: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, query), params), values), {}, {
          jobId: jobId,
          timeStart: timeStart ? moment(timeStart).format(DEFAULT_DATETIME_FORMAT) : null,
          timeEnd: timeEnd ? moment(timeEnd).format(DEFAULT_DATETIME_FORMAT) : null
        })
      });
    }
    /**
     * @function handleSearch - 搜索表单
     */

  }, {
    key: "handleSearch",
    value: function handleSearch() {
      var _this3 = this;

      var form = this.props.form;
      form.validateFields(function (err) {
        if (_isEmpty(err)) {
          _this3.fetchLogsList({
            page: 0,
            size: 10
          });
        }
      });
    }
    /**
     * 重置
     */

  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      var form = this.props.form;
      form.resetFields();
    }
    /**
     * 多查询条件展示
     */

  }, {
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    } // 调度日志

  }, {
    key: "showTriggerMsgModal",
    value: function showTriggerMsgModal(record) {
      var _this4 = this;

      this.setState({
        triggerMsgData: record
      }, function () {
        _this4.handleModalVisible(true);
      });
    } // 拉取执行日志

  }, {
    key: "pullLog",
    value: function pullLog() {
      var _this5 = this;

      var dispatch = this.props.dispatch;
      var _this$state = this.state,
          logContent = _this$state.logContent,
          fromLineNum = _this$state.fromLineNum,
          pullFailCount = _this$state.pullFailCount,
          _this$state$queryPara = _this$state.queryParams,
          logId = _this$state$queryPara.logId,
          executorAddress = _this$state$queryPara.executorAddress,
          triggerTime = _this$state$queryPara.triggerTime;
      var tempPullFailCount = pullFailCount;

      if (tempPullFailCount++ > 20) {
        this.setState({
          pullLoading: false,
          tipsMessage: {
            color: 'red',
            content: "<span style=\"color: red;\">".concat(intl.get('csdr.jobLog.view.message.pullLogTips').d('终止请求Rolling日志,请求失败次数超上限,可刷新页面重新加载日志'), "</span>")
          }
        });
        this.handleClearTimer();
        return;
      }

      dispatch({
        type: 'jobLog/fetchLogsCat',
        payload: {
          logId: logId,
          executorAddress: executorAddress,
          fromLineNum: fromLineNum,
          triggerTime: triggerTime
        }
      }).then(function (data) {
        if (data) {
          if (fromLineNum !== data.fromLineNum) {
            return;
          }

          if (fromLineNum > data.toLineNum) {
            if (data.end) {
              _this5.setState(_objectSpread(_objectSpread({}, _this5.state), {}, {
                pullLoading: false,
                tipsMessage: '<br><span style="color: green;">[Rolling Log Finish]</span>'
              }));

              _this5.handleClearTimer();
            }
          }

          _this5.setState(_objectSpread(_objectSpread({}, _this5.state), {}, {
            fromLineNum: data.toLineNum + 1,
            logContent: logContent + data.logContent,
            pullFailCount: 0
          }));

          if (!_this5.state.handleMsgVisible) return;
          var wrapEl = document.querySelector('.ant-modal-body'); // const wrapEl = ReactDOM.findDOMNode(this.handleMsgDrawer).querySelector('.ant-modal-body'); // [TODO]

          wrapEl.scrollTo(0, wrapEl.scrollHeight);
        }
      });
    } // 执行日志

  }, {
    key: "showHandleMsgModal",
    value: function showHandleMsgModal(record) {
      var _this6 = this;

      var id = record.id,
          executorAddress = record.executorAddress,
          triggerTime = record.triggerTime,
          handleCode = record.handleCode;
      this.setState({
        queryParams: {
          logId: id,
          executorAddress: executorAddress,
          triggerTime: triggerTime ? Date.parse(triggerTime.replace(/-/g, '/')) : null
        },
        tipsMessage: handleCode > 0 ? '<br><span style="color: green;">[Load Log Finish]</span>' : '',
        pullLoading: !(handleCode > 0)
      }, function () {
        _this6.handleMsgModalVisible(true); // 打开模态框的时候要拉取日志


        _this6.pullLog();

        _this6.pullCatTimer = setInterval(function () {
          return _this6.pullLog();
        }, 3000);

        if (handleCode > 0) {
          _this6.setState(_objectSpread(_objectSpread({}, _this6.state), {}, {
            pullLoading: false,
            tipsMessage: '<br><span style="color: green;">[Load Log Finish]</span>'
          }));

          _this6.handleClearTimer();
        }
      });
    }
    /**
     *是否打开详情模态框
     *
     * @param {boolean} flag true--打开 false--关闭
     * @memberof Tenants
     */

  }, {
    key: "handleDetailModalVisible",
    value: function handleDetailModalVisible(flag) {
      this.setState({
        detailVisible: !!flag
      });
    }
    /**
     *是否打开调度日志模态框
     *
     * @param {boolean} flag true--打开 false--关闭
     * @memberof Tenants
     */

  }, {
    key: "handleModalVisible",
    value: function handleModalVisible(flag) {
      this.setState({
        modalVisible: !!flag
      });
    }
    /**
     *是否打开执行日志模态框
     *
     * @param {boolean} flag true--打开 false--关闭
     * @memberof Tenants
     */

  }, {
    key: "handleMsgModalVisible",
    value: function handleMsgModalVisible(flag) {
      this.handleClearTimer(); // 执行日志弹窗关闭后重置参数

      this.setState(_objectSpread(_objectSpread({}, this.state), {}, {
        handleMsgVisible: !!flag,
        pullLoading: true,
        logContent: '',
        tipsMessage: '',
        fromLineNum: 1,
        pullFailCount: 0
      }));
    }
    /**
     *是否打开清除日志模态框
     *
     * @param {boolean} flag true--打开 false--关闭
     */

  }, {
    key: "handleClearLogsModalVisible",
    value: function handleClearLogsModalVisible(flag) {
      this.setState({
        clearLogsVisible: flag
      });
    }
  }, {
    key: "showClearLogDrawer",
    value: function showClearLogDrawer() {
      this.handleClearLogsModalVisible(true);
    }
  }, {
    key: "hideClearLogDrawer",
    value: function hideClearLogDrawer() {
      this.handleClearLogsModalVisible(false);
    }
    /**
     * handleStandardTableChange-Table 分页信息改变
     */

  }, {
    key: "handleStandardTableChange",
    value: function handleStandardTableChange(pagination) {
      var query = this.props.query;

      var params = _objectSpread({
        page: pagination.current - 1,
        size: pagination.pageSize
      }, query);

      this.fetchLogsList(params);
    }
    /**
     * 数据列表，删除
     * @param {obejct} record - 操作对象
     */

  }, {
    key: "handleDeleteContent",
    value: function handleDeleteContent(record) {
      var _this7 = this;

      var _this$props4 = this.props,
          dispatch = _this$props4.dispatch,
          pagination = _this$props4.jobLog.pagination;
      dispatch({
        type: 'jobLog/deleteLogs',
        payload: {
          logId: record.logId,
          jobId: record.jobId,
          _token: record._token
        }
      }).then(function (res) {
        if (res) {
          notification.success();

          _this7.fetchLogsList({
            page: pagination.current - 1,
            size: pagination.pageSize
          });
        }
      });
    }
    /**
     * 下载
     * @param {object} record - 流程对象
     */

  }, {
    key: "downloadLogFile",
    value: function downloadLogFile(record) {
      var tenantRoleLevel = this.props.tenantRoleLevel;
      var tenantId = record.tenantId;
      var api = tenantRoleLevel ? "".concat(CPAAS_FILE, "/v1/").concat(tenantId, "/files/download") : "".concat(CPAAS_FILE, "/v1/files/download");

      if (record.logFlag === 1) {
        this.showLogModal(record);
      }

      if (record.logFlag === 0 && record.logUrl !== '') {
        downloadFile({
          requestUrl: api,
          queryParams: [{
            name: 'bucketName',
            value: BKT_SDR
          }, {
            name: 'directory',
            value: 'csdr01'
          }, {
            name: 'url',
            value: record.logUrl
          }]
        });
      }
    }
    /**
     * @function renderForm - 渲染搜索表单
     */

  }, {
    key: "renderFilterForm",
    value: function renderFilterForm() {
      var _this$props5 = this.props,
          dateTimeFormat = _this$props5.dateTimeFormat,
          _this$props5$form = _this$props5.form,
          getFieldDecorator = _this$props5$form.getFieldDecorator,
          getFieldValue = _this$props5$form.getFieldValue,
          tenantRoleLevel = _this$props5.tenantRoleLevel,
          _this$props5$jobLog = _this$props5.jobLog,
          _this$props5$jobLog$j = _this$props5$jobLog.jobResultList,
          jobResultList = _this$props5$jobLog$j === void 0 ? [] : _this$props5$jobLog$j,
          _this$props5$jobLog$c = _this$props5$jobLog.clientResultList,
          clientResultList = _this$props5$jobLog$c === void 0 ? [] : _this$props5$jobLog$c;
      var _this$state$expandFor = this.state.expandForm,
          expandForm = _this$state$expandFor === void 0 ? true : _this$state$expandFor;
      return /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        type: "flex",
        gutter: 24,
        align: "bottom"
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.jobId').d('任务ID')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('taskId', {
        rules: [{
          pattern: /^[0-9]*$/,
          message: intl.get('csdr.concRequest.validation.digital').d('只能输入数字')
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.jobResult').d('调度结果')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('jobResult')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, jobResultList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.clientResult').d('客户端执行结果')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('clientResult')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, clientResultList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: "search-btn-more"
      }), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.toggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get('cpaas.common.button.viewMore').d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, {
        type: "flex",
        align: "bottom",
        gutter: 24,
        style: expandForm ? expandFormStyle : noExpandFormStyle
      }, !tenantRoleLevel && /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get('csdr.jobLog.model.jobLog.tenantName').d('租户')
      }), getFieldDecorator('tenantId')( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT"
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.executorName').d('执行器名称')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('executorName', {})( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.jobCode').d('任务编码')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('jobCode')( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        typeCase: "upper",
        inputChinese: false
      })))), tenantRoleLevel && /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.description').d('任务描述')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('description')( /*#__PURE__*/React.createElement(Input, {
        trim: true
      }))))), /*#__PURE__*/React.createElement(Row, {
        type: "flex",
        align: "bottom",
        gutter: 24,
        style: expandForm ? expandFormStyle : noExpandFormStyle
      }, !tenantRoleLevel && /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.description').d('任务描述')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('description')( /*#__PURE__*/React.createElement(Input, {
        trim: true
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.startTime').d('执行开始时间')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('timeStart')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: {
          format: DEFAULT_TIME_FORMAT
        },
        format: dateTimeFormat,
        placeholder: "",
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('timeEnd') && moment(getFieldValue('timeEnd')).isBefore(currentDate, 'day');
        }
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(Form.Item, Object.assign({
        label: intl.get('csdr.jobLog.model.jobLog.endTime').d('执行结束时间')
      }, SEARCH_FORM_ITEM_LAYOUT), getFieldDecorator('timeEnd')( /*#__PURE__*/React.createElement(DatePicker, {
        showTime: {
          format: DEFAULT_TIME_FORMAT
        },
        format: dateTimeFormat,
        placeholder: "",
        disabledDate: function disabledDate(currentDate) {
          return getFieldValue('timeStart') && moment(getFieldValue('timeStart')).isAfter(currentDate, 'day');
        }
      }))))));
    }
  }, {
    key: "showErrorModal",
    value: function showErrorModal(record) {
      var _this8 = this;

      var dispatch = this.props.dispatch;
      this.setState({
        errorVisible: true
      }, function () {
        dispatch({
          type: 'jobLog/fetchErrorDetail',
          payload: {
            logId: record.logId
          }
        }).then(function (res) {
          if (res) {
            _this8.setState({
              errorDetail: res
            });
          }
        });
      });
    }
  }, {
    key: "closeErrorModal",
    value: function closeErrorModal() {
      this.setState({
        errorVisible: false,
        errorDetail: ''
      });
    }
  }, {
    key: "showLogModal",
    value: function showLogModal(record) {
      var _this9 = this;

      var dispatch = this.props.dispatch;
      this.setState({
        logVisible: true
      }, function () {
        dispatch({
          type: 'jobLog/fetchLogDetail',
          payload: {
            logId: record.logId
          }
        }).then(function (res) {
          if (res) {
            _this9.setState({
              logDetail: res
            });
          }
        });
      });
    }
  }, {
    key: "closeLogModal",
    value: function closeLogModal() {
      this.setState({
        logVisible: false,
        logDetail: ''
      });
    } // 获取任务进度

  }, {
    key: "fetchProgress",
    value: function fetchProgress(record) {
      var _this10 = this;

      var dispatch = this.props.dispatch;
      dispatch({
        type: 'jobLog/fetchProgress',
        payload: {
          logId: record.logId
        }
      }).then(function (res) {
        if (res) {
          _this10.setState({
            progressValue: JSON.parse(res)
          });

          if (res.progress === 100) {
            _this10.clearProgressTimer();

            notification.info({
              message: intl.get('csdr.jobLog.model.jobLog.showInfo').d('任务已执行完成！')
            });
          }
        }
      });
    } // 打开任务进度弹窗

  }, {
    key: "showProgressModal",
    value: function showProgressModal(record) {
      var _this11 = this;

      this.setState({
        progressVisible: true
      }, function () {
        _this11.fetchProgress(record);

        _this11.progressTimer = setInterval(function () {
          return _this11.fetchProgress(record);
        }, 5000);
      });
    } // 关闭任务进度弹窗

  }, {
    key: "closeProgressModal",
    value: function closeProgressModal() {
      var _this12 = this;

      var _this$props$jobLog = this.props.jobLog,
          skipQuery = _this$props$jobLog.skipQuery,
          pagination = _this$props$jobLog.pagination;
      this.setState({
        progressVisible: false
      }, function () {
        _this12.clearProgressTimer();

        _this12.fetchLogsList({
          jobId: skipQuery.jobId,
          page: pagination.current - 1,
          size: pagination.pageSize
        });
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this13 = this;

      var _this$props6 = this.props,
          fetchList = _this$props6.fetchList,
          _this$props6$jobLog = _this$props6.jobLog,
          _this$props6$jobLog$j = _this$props6$jobLog.jobLogList,
          jobLogList = _this$props6$jobLog$j === void 0 ? [] : _this$props6$jobLog$j,
          pagination = _this$props6$jobLog.pagination,
          _this$props6$jobLog$c = _this$props6$jobLog.clearTypeList,
          clearTypeList = _this$props6$jobLog$c === void 0 ? [] : _this$props6$jobLog$c,
          tenantRoleLevel = _this$props6.tenantRoleLevel,
          errorDetailLoading = _this$props6.errorDetailLoading,
          logDetailLoading = _this$props6.logDetailLoading,
          _this$props6$clearLog = _this$props6.clearLogLoading,
          clearLogLoading = _this$props6$clearLog === void 0 ? false : _this$props6$clearLog,
          path = _this$props6.match.path;
      var _this$state2 = this.state,
          errorVisible = _this$state2.errorVisible,
          errorDetail = _this$state2.errorDetail,
          logVisible = _this$state2.logVisible,
          logDetail = _this$state2.logDetail,
          progressVisible = _this$state2.progressVisible,
          progressValue = _this$state2.progressValue,
          clearLogsVisible = _this$state2.clearLogsVisible;
      var errorProps = {
        errorDetailLoading: errorDetailLoading,
        errorDetail: errorDetail,
        errorVisible: errorVisible,
        onOk: this.closeErrorModal
      };
      var logProps = {
        logDetailLoading: logDetailLoading,
        logDetail: logDetail,
        logVisible: logVisible,
        onOk: this.closeLogModal
      };
      var progressProps = {
        progressVisible: progressVisible,
        progressValue: progressValue,
        onOk: this.closeProgressModal
      };
      var columns = [{
        title: intl.get('csdr.jobLog.model.jobLog.jobId').d('任务ID'),
        width: 100,
        dataIndex: 'taskId'
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.jobCode').d('任务编码'),
        width: 150,
        dataIndex: 'jobCode'
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.description').d('任务描述'),
        dataIndex: 'description'
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.tenantName').d('租户'),
        width: 150,
        dataIndex: 'tenantName'
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.jobResult').d('调度结果'),
        width: 100,
        dataIndex: 'jobResultMeaning',
        render: function render(text, record) {
          var statusList = [{
            status: 'SUCCESS',
            color: 'green'
          }, {
            status: 'FAILURE',
            color: 'red'
          }, {
            status: 'DOING',
            color: ''
          }];
          return TagRender(record.jobResult, statusList, text);
        }
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.clientResult').d('客户端执行结果'),
        dataIndex: 'clientResultMeaning',
        width: 120,
        render: function render(text, record) {
          var statusList = [{
            status: 'SUCCESS',
            color: 'green'
          }, {
            status: 'FAILURE',
            color: 'red'
          }, {
            status: 'WARNING',
            color: 'orange'
          }, {
            status: 'DOING',
            color: ''
          }];
          return TagRender(record.clientResult, statusList, text);
        }
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.executorName').d('执行器名称'),
        dataIndex: 'executorName',
        width: 150
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.address').d('执行地址'),
        dataIndex: 'address',
        width: 150
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.startTime').d('执行开始时间'),
        width: 150,
        dataIndex: 'startTime',
        render: dateTimeRender
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.endTime').d('执行结束时间'),
        width: 150,
        dataIndex: 'endTime',
        render: dateTimeRender
      }, {
        title: intl.get('csdr.jobLog.model.jobLog.message').d('错误信息'),
        dataIndex: 'messageHeader',
        width: 250
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 200,
        dataIndex: 'operator',
        fixed: 'right',
        render: function render(text, record) {
          var operators = [];

          if (record.clientResult === 'FAILURE') {
            operators.push({
              key: 'errorDetail',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.errorDetail"),
                  type: 'button',
                  meaning: '调度日志-错误详情'
                }],
                onClick: function onClick() {
                  return _this13.showErrorModal(record);
                }
              }, intl.get('csdr.jobLog.model.jobLog.errorDetail').d('错误详情')),
              len: 4,
              title: intl.get('csdr.jobLog.model.jobLog.errorDetail').d('错误详情')
            });
          }

          if (record.logUrl && record.logFlag === 0 || record.logFlag === 1) {
            operators.push({
              key: 'logDetail',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.logUrl"),
                  type: 'button',
                  meaning: '调度日志-日志文件'
                }],
                onClick: function onClick() {
                  return _this13.downloadLogFile(record);
                }
              }, record.logFlag === 1 ? intl.get('csdr.jobLog.model.jobLog.logDetail').d('日志详情') : intl.get('csdr.jobLog.model.jobLog.logUrl').d('日志文件')),
              len: 4,
              title: record.logFlag === 1 ? intl.get('csdr.jobLog.model.jobLog.logDetail').d('日志详情') : intl.get('csdr.jobLog.model.jobLog.logUrl').d('日志文件')
            });
          }

          if (record.clientResult === 'DOING') {
            operators.push({
              key: 'taskProgress',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.taskProgress"),
                  type: 'button',
                  meaning: '调度日志-任务进度'
                }],
                onClick: function onClick() {
                  return _this13.showProgressModal(record);
                }
              }, intl.get('csdr.jobLog.model.jobLog.taskProgress').d('任务进度')),
              len: 4,
              title: intl.get('csdr.jobLog.model.jobLog.taskProgress').d('任务进度')
            });
          }

          operators.push({
            key: 'delete',
            ele: /*#__PURE__*/React.createElement(Popconfirm, {
              placement: "topRight",
              title: intl.get('cpaas.common.message.confirm.delete').d('是否删除此条记录？'),
              onConfirm: function onConfirm() {
                return _this13.handleDeleteContent(record);
              }
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.delete"),
                type: 'button',
                meaning: '调度日志-删除'
              }]
            }, intl.get('cpaas.common.button.delete').d('删除'))),
            len: 2,
            title: intl.get('cpaas.common.button.delete').d('删除')
          });
          return operatorRender(operators, record, {
            limit: 3
          });
        }
      }].filter(function (col) {
        return tenantRoleLevel ? col.dataIndex !== 'tenantName' : true;
      });
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, {
        title: intl.get('csdr.jobLog.view.message.title').d('调度日志')
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        type: "primary",
        icon: "delete",
        onClick: this.showClearLogDrawer,
        permissionList: [{
          code: "".concat(path, ".button.clearLogs"),
          type: 'button',
          meaning: '调度日志-日志清理'
        }]
      }, intl.get('csdr.jobLog.view.button.clearLogs').d('日志清理'))), /*#__PURE__*/React.createElement(Content, null, this.renderFilterForm(), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "logId",
        loading: fetchList,
        dataSource: jobLogList,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns, 200)
        },
        pagination: pagination,
        onChange: this.handleStandardTableChange
      }), /*#__PURE__*/React.createElement(ClearLogsDrawer, {
        title: intl.get('csdr.jobLog.view.button.clearLogs').d('日志清理'),
        loading: clearLogLoading,
        modalVisible: clearLogsVisible,
        clearTypeList: clearTypeList,
        onCancel: this.hideClearLogDrawer,
        onOk: this.handleClearLogs
      }), errorVisible && /*#__PURE__*/React.createElement(ErrorModal, errorProps), logVisible && /*#__PURE__*/React.createElement(LogModal, logProps), progressVisible && /*#__PURE__*/React.createElement(ProgressModal, progressProps)));
    }
  }]);

  return JobLog;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "handleClearTimer", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleClearTimer"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "clearProgressTimer", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "clearProgressTimer"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleClearLogs", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleClearLogs"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showTriggerMsgModal", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "showTriggerMsgModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "pullLog", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "pullLog"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showHandleMsgModal", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "showHandleMsgModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showClearLogDrawer", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "showClearLogDrawer"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hideClearLogDrawer", [_dec14], Object.getOwnPropertyDescriptor(_class2.prototype, "hideClearLogDrawer"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleStandardTableChange", [_dec15], Object.getOwnPropertyDescriptor(_class2.prototype, "handleStandardTableChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDeleteContent", [_dec16], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDeleteContent"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "downloadLogFile", [_dec17], Object.getOwnPropertyDescriptor(_class2.prototype, "downloadLogFile"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showErrorModal", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "showErrorModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "closeErrorModal", [_dec19], Object.getOwnPropertyDescriptor(_class2.prototype, "closeErrorModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showLogModal", [_dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "showLogModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "closeLogModal", [_dec21], Object.getOwnPropertyDescriptor(_class2.prototype, "closeLogModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchProgress", [_dec22], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchProgress"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showProgressModal", [_dec23], Object.getOwnPropertyDescriptor(_class2.prototype, "showProgressModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "closeProgressModal", [_dec24], Object.getOwnPropertyDescriptor(_class2.prototype, "closeProgressModal"), _class2.prototype)), _class2)) || _class) || _class) || _class);
export { JobLog as default };